package com.drinks.yiniang.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;

import com.drinks.yiniang.common.help.UserTokenSingleton;
import com.drinks.yiniang.ui.activity.category.CategoryActivity;
import com.drinks.yiniang.ui.activity.community.CommunityDetailActivity;
import com.drinks.yiniang.ui.activity.goods.GoodsDetailsActivity;
import com.drinks.yiniang.ui.activity.goods.RecommendGoodsActivity;
import com.drinks.yiniang.ui.activity.user.achievement.AchievementActivity;
import com.drinks.yiniang.ui.activity.user.login.LoginActivity;
import com.drinks.yiniang.ui.activity.user.order.MyOrderActivity;
import com.drinks.yiniang.ui.activity.user.order.OrderDetailsActivity;
import com.drinks.yiniang.ui.activity.user.points.CouponActivity;
import com.drinks.yiniang.ui.activity.user.wine.WineListDetailActivity;
import com.hansen.library.Constants;
import com.hansen.library.utils.StringUtils;

/**
 * @author han
 * @date 2019/12/3
 */
public class ActivityUtils {

    public static void startActivityByAdType(Context context, String type, String value) {
        if(StringUtils.isEmpty(type)) {
            return;
        }

        Intent mIntent;

        //类型 0-商品；1-酒单；2-套餐（取消）；3-分类；4-活动；5-社区文章；6-智能推荐
        switch (type) {
            case "0"://商品
                mIntent = new Intent(context, GoodsDetailsActivity.class);
                mIntent.putExtra(Constants.KeyGoodsId, value);
                context.startActivity(mIntent);
                break;
            case "1"://酒单
                mIntent = new Intent(context, WineListDetailActivity.class);
                mIntent.putExtra(Constants.KeyId, value);
                context.startActivity(mIntent);
                break;
            case "2"://套餐
                break;
            case "3"://分类
                mIntent = new Intent(context, CategoryActivity.class);
                mIntent.putExtra(Constants.KeyCategoryId, value);
                context.startActivity(mIntent);
                break;
            case "4"://活动
                break;
            case "5"://社区文章
                mIntent = new Intent(context, CommunityDetailActivity.class);
                mIntent.putExtra(Constants.KeyCommunityId, value);
                context.startActivity(mIntent);
                break;
            case "6"://智能推荐
                mIntent = new Intent(context, RecommendGoodsActivity.class);
                context.startActivity(mIntent);
                break;
            default:
                break;
        }
    }

    public static void startActivityByMsgType(Context context, String type, String value) {
        if(StringUtils.isEmpty(type)) {
            return;
        }

        Intent mIntent;

        //关联类型 0系统消息 1订单 2社区文章收藏 3社区文章点赞 4关注 5优惠券 6社区文章加精 7勋章
        switch (type) {
            case "0"://系统消息
                break;
            case "1"://订单
                mIntent = new Intent(context, MyOrderActivity.class);
                context.startActivity(mIntent);
                break;
            case "2"://社区文章收藏
            case "3"://社区文章点赞
            case "6"://社区文章加精
                mIntent = new Intent(context, CommunityDetailActivity.class);
                mIntent.putExtra(Constants.KeyCommunityId, value);
                context.startActivity(mIntent);
                break;
            case "4"://关注
                break;
            case "5"://优惠券
                mIntent = new Intent(context, CouponActivity.class);
                mIntent.putExtra(Constants.KeyType, Constants.TYPE_COUPON_COMMON);
                context.startActivity(mIntent);
                break;
            case "7"://勋章
                mIntent = new Intent(context, AchievementActivity.class);
                context.startActivity(mIntent);
                break;
            default:
                break;
        }
    }

    //判断是否登录
    public static boolean isLogined(Activity context, boolean isToLogin) {
        if(StringUtils.isEmpty(UserTokenSingleton.getInstance().getGlobalUserToken())) {//判断是否登录
            if(isToLogin) {
                context.startActivityForResult(new Intent(context, LoginActivity.class), Constants.REQ_LOGIN_CODE);
            }

            return false;
        }

        return true;
    }

    //判断是否登录
    public static boolean isLogined(Fragment fragment, Context context, boolean isToLogin) {
        if(StringUtils.isEmpty(UserTokenSingleton.getInstance().getGlobalUserToken())) {//判断是否登录
            if(isToLogin) {
                fragment.startActivityForResult(new Intent(context, LoginActivity.class), Constants.REQ_LOGIN_CODE);
            }

            return false;
        }

        return true;
    }
}
